<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "../hooks";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    code: "",
    remark: ""
  })
});
const { switchStyle } = usePublicHooks();
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
const sexOptions = [
  {
    value: 1,
    label: "内置"
  },
  {
    value: 2,
    label: "自定义"
  }
];
defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="角色名称" prop="roleName">
      <el-input
        v-model="newFormInline.roleName"
        clearable
        placeholder="请输入角色名称"
      />
    </el-form-item>

    <el-form-item label="角色标识" prop="roleFalg">
      <el-input
        v-model="newFormInline.roleFalg"
        clearable
        placeholder="请输入角色标识"
      />
    </el-form-item>
    <el-form-item label="角色类型" prop="roleType">
      <el-select
        v-model="newFormInline.roleType"
        placeholder="请选择角色类型"
        class="w-full"
        clearable
      >
        <el-option
          v-for="(item, index) in sexOptions"
          :key="index"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="角色状态">
      <el-switch
        v-model="newFormInline.disate"
        inline-prompt
        :active-value="1"
        :inactive-value="0"
        active-text="启用"
        inactive-text="停用"
        :style="switchStyle"
      />
    </el-form-item>

    <el-form-item label="排序">
      <el-input-number
        v-model="newFormInline.disSort"
        :min="0"
        :max="9999"
        controls-position="right"
      />
    </el-form-item>

    <el-form-item label="备注">
      <el-input
        v-model="newFormInline.remark"
        placeholder="请输入备注信息"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template>
